package com.ruoyi.wms.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.QualityInspectionItemMapper;
import com.ruoyi.wms.domain.QualityInspectionItem;
import com.ruoyi.wms.service.IQualityInspectionItemService;

/**
 * QualityInspectionItemService业务层处理
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@Service
public class QualityInspectionItemServiceImpl implements IQualityInspectionItemService {
    @Autowired
    private QualityInspectionItemMapper qualityInspectionItemMapper;

    /**
     * 查询QualityInspectionItem
     *
     * @param id QualityInspectionItem主键
     * @return QualityInspectionItem
     */
    @Override
    public QualityInspectionItem selectQualityInspectionItemById(String id) {
        return qualityInspectionItemMapper.selectQualityInspectionItemById(id);
    }

    /**
     * 查询QualityInspectionItem列表
     *
     * @param qualityInspectionItem QualityInspectionItem
     * @return QualityInspectionItem
     */
    @Override
    public List<QualityInspectionItem> selectQualityInspectionItemList(QualityInspectionItem qualityInspectionItem) {
        return qualityInspectionItemMapper.selectQualityInspectionItemList(qualityInspectionItem);
    }

    /**
     * 新增QualityInspectionItem
     *
     * @param qualityInspectionItem QualityInspectionItem
     * @return 结果
     */
    @Override
    public int insertQualityInspectionItem(QualityInspectionItem qualityInspectionItem) {


        qualityInspectionItem.setId(MD5Utils.md5(  qualityInspectionItem.getPlateNo()+qualityInspectionItem.getColName() ));
        qualityInspectionItem.setCreateUser(SecurityUtils.getUsername());
        qualityInspectionItem.setCreateDate(DateUtils.getCurrentTime());

        return qualityInspectionItemMapper.insertQualityInspectionItem(qualityInspectionItem);
    }

    /**
     * 修改QualityInspectionItem
     *
     * @param qualityInspectionItem QualityInspectionItem
     * @return 结果
     */
    @Override
    public int updateQualityInspectionItem(QualityInspectionItem qualityInspectionItem) {

        int updateResult = 0;
        if (StringUtils.isEmpty(qualityInspectionItem.getId())) {
            updateResult = insertQualityInspectionItem(qualityInspectionItem);
        }
         updateResult =  qualityInspectionItemMapper.updateQualityInspectionItem(qualityInspectionItem);
        if (0 == updateResult) {
            updateResult = insertQualityInspectionItem(qualityInspectionItem);
        }

        return updateResult;



    }

    /**
     * 批量删除QualityInspectionItem
     *
     * @param ids 需要删除的QualityInspectionItem主键
     * @return 结果
     */
    @Override
    public int deleteQualityInspectionItemByIds(String[] ids) {
        return qualityInspectionItemMapper.deleteQualityInspectionItemByIds(ids);
    }

    /**
     * 删除QualityInspectionItem信息
     *
     * @param id QualityInspectionItem主键
     * @return 结果
     */
    @Override
    public int deleteQualityInspectionItemById(String id) {
        return qualityInspectionItemMapper.deleteQualityInspectionItemById(id);
    }
}
